home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / grafik / raystorm / examples / worldanim.cpp < prev    next >
Text File  |  1995-08-10  |  5KB  |  199 lines

  1. /***************
  2.  * NAME:          worldanim.cpp
  3.  * VERSION:       1.0 10.08.1995
  4.  * DESCRIPTION:   Example program for RayStorm
  5.  *                        this program has been compiled with Maxon C++ 3.0
  6.  *    AUTHORS:            Andreas Heumann, Mike Hesser
  7.  * BUGS:          none
  8.  * TO DO:         
  9.  * HISTORY:       DATE        NAME    COMMENT
  10.  *                        10.08.95    ah        first release
  11.  ***************/
  12.  
  13. #include <exec/memory.h>
  14. #include <rexx/storage.h>
  15. #include <rexx/rxslib.h>
  16. #include <exec/types.h>
  17.  
  18. #include <pragma/exec_lib.h>
  19. #include <pragma/rexxsyslib_lib.h>
  20.  
  21. #include <fstream.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <math.h>
  26.  
  27. struct Library *RexxSysBase = NULL;
  28. static struct MsgPort *HostPort;
  29. static struct MsgPort *ReplyPort = NULL;
  30.  
  31. static int msgs = 0;        // remaining messages
  32.  
  33. /*************
  34.  * FUNCTION:        cleanup
  35.  * VERSION:            1.0 08.05.1995
  36.  * DESCRIPTION:    close libs ...
  37.  * INPUT:            none
  38.  * OUTPUT:            none
  39.  * HISTORY:       DATE        NAME        COMMENT
  40.  *                        08.05.95    ah            first release
  41.  *************/
  42. void cleanup()
  43. {
  44.     struct RexxMsg *RexxMessage;
  45.  
  46.     if(ReplyPort)
  47.     {
  48.         // free messages
  49.         while(msgs)
  50.         {
  51.             // Wait for message
  52.             WaitPort(ReplyPort);
  53.             // get messages
  54.             while(RexxMessage = (struct RexxMsg*)GetMsg(ReplyPort))
  55.             {
  56.                 // Remove Rexx message
  57.                 ClearRexxMsg(RexxMessage,1);
  58.                 DeleteRexxMsg(RexxMessage);
  59.                 msgs--;
  60.             }
  61.         }
  62.         // Free reply port signal bit
  63.         FreeSignal(ReplyPort->mp_SigBit);
  64.         // Free the replyport itself
  65.         FreeMem(ReplyPort,sizeof(struct MsgPort));
  66.     }
  67.     if (RexxSysBase)
  68.         CloseLibrary(RexxSysBase);
  69.     exit(0);
  70. }
  71.  
  72. /*************
  73.  * FUNCTION:        SendRexxMsg
  74.  * VERSION:            1.0 08.05.1995
  75.  * DESCRIPTION:    Sends a single command to Rexx host
  76.  * INPUT:            HostPort        pointer to host message port
  77.  *                        SingleMsg    message to send
  78.  * OUTPUT:            none
  79.  * HISTORY:       DATE        NAME        COMMENT
  80.  *                        08.05.95    ah            first release
  81.  *************/
  82. void SendRexxMsg(struct MsgPort *HostPort, char *SingleMsg)
  83. {
  84.     struct RexxMsg *RexxMessage;
  85.  
  86.     // free previous messages
  87.     while(RexxMessage = (struct RexxMsg*)GetMsg(ReplyPort))
  88.     {
  89.         // Remove Rexx message
  90.         ClearRexxMsg(RexxMessage,1);
  91.         DeleteRexxMsg(RexxMessage);
  92.         msgs--;
  93.     }
  94.  
  95.     // Valid pointers given?
  96.     if(HostPort && SingleMsg)
  97.     {
  98.         // Create a Rexx message
  99.         RexxMessage = (struct RexxMsg *)CreateRexxMsg(ReplyPort,"",NULL);
  100.         if(RexxMessage)
  101.         {
  102.             RexxMessage->rm_Args[0] = CreateArgstring(SingleMsg, strlen(SingleMsg));
  103.             RexxMessage->rm_Action = RXFF_RESULT;
  104.  
  105.             // Send packet
  106.             PutMsg(HostPort,(struct Message *)RexxMessage);
  107.             msgs++;
  108.         }
  109.     }
  110. }
  111.  
  112. /*************
  113.  * FUNCTION:        Init
  114.  * VERSION:            1.0 08.05.1995
  115.  * DESCRIPTION:    Open libs, init ports
  116.  * INPUT:            none
  117.  * OUTPUT:            none
  118.  * HISTORY:       DATE        NAME        COMMENT
  119.  *                        08.05.95    ah            first release
  120.  *************/
  121. void Init()
  122. {
  123.     // is raystrom already active ?
  124.     HostPort = (struct MsgPort *)FindPort("RAYSTORM");
  125.     if(!HostPort)
  126.     {
  127.         cout << "Raystorm is not running please start it\n";
  128.         cleanup();
  129.     }
  130.     // Allocate a reply port
  131.     ReplyPort = (struct MsgPort *)AllocMem(sizeof(struct MsgPort),MEMF_PUBLIC | MEMF_CLEAR);
  132.     if(ReplyPort)
  133.     {
  134.         ReplyPort->mp_SigBit = AllocSignal(-1);
  135.         if(ReplyPort->mp_SigBit != -1)
  136.         {
  137.             ReplyPort->mp_Node.ln_Type    = NT_MSGPORT;
  138.             ReplyPort->mp_Flags            = PA_SIGNAL;
  139.             ReplyPort->mp_SigTask        = FindTask(NULL);
  140.  
  141.             ReplyPort->mp_MsgList.lh_Head = (struct Node *)&ReplyPort->mp_MsgList.lh_Tail;
  142.             ReplyPort->mp_MsgList.lh_Tail = 0;
  143.             ReplyPort->mp_MsgList.lh_TailPred = (struct Node *)&ReplyPort->mp_MsgList.lh_Head;
  144.         }
  145.     }
  146.  
  147.     // Open rexxsyslib library.
  148.     RexxSysBase = OpenLibrary("rexxsyslib.library",0L);
  149.     if (!RexxSysBase)
  150.     {
  151.         cout << "Can't open rexxsyslib.library\n";
  152.         cleanup();
  153.     }
  154. }
  155.  
  156. void main(int argc, char *argv[])
  157. {
  158.     float f;
  159.     int i, pics;
  160.     char buffer[256];
  161.  
  162.     // Parse arguments
  163.     if(argc != 2)
  164.     {
  165.         cout << "Worldanim V1.0 1995 by Andreas Heumann\n";
  166.         cout << "Usage: worldanim picnum\n";
  167.         cout << "   picnum - amount of pictures to create\n";
  168.         cleanup();
  169.     }
  170.     sscanf(argv[1],"%d",&pics);
  171.     if(pics<2)
  172.     {
  173.         cout << "I need at least two pictures to create.\n";
  174.         cleanup();
  175.     }
  176.     pics--;
  177.  
  178.     Init();
  179.  
  180.     i=1;
  181.     for(f=0; f<360; f+=360/pics)
  182.     {
  183.         SendRexxMsg(HostPort, "SETSCREEN 160 128");
  184.         SendRexxMsg(HostPort, "SETWORLD 0 0 0  100 100 100");
  185.         SendRexxMsg(HostPort, "SETCAMERA 0 0 4  0 0 0  0 1 0  56.25 45");
  186.         SendRexxMsg(HostPort, "POINTLIGHT 5 5 10 255 255 255");
  187.         SendRexxMsg(HostPort, "NEWSURFACE EARTH");
  188.         sprintf(buffer, "BRUSH /brushes/earth.iff COLOR WRAPXY 0 0 0  0 %d 0  .1 .1 .1", int(f));
  189.         SendRexxMsg(HostPort, buffer);
  190.         SendRexxMsg(HostPort, "SPHERE EARTH 0 0 0 1");
  191.         SendRexxMsg(HostPort, "STARTRENDER QUICK");
  192.         sprintf(buffer, "SAVEPIC pics/pic.%04d", i);
  193.         SendRexxMsg(HostPort, buffer);
  194.         SendRexxMsg(HostPort, "CLEANUP");
  195.         i++;
  196.     }
  197.  
  198.     cleanup();
  199. }